package com.example.myworkers.controller;

import com.example.myworkers.model.EmpCancel;
import com.example.myworkers.service.EmpCancelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 销假管理
 *
 * @Author 吴秋霞
 * @Date 2023/11/1 0:39
 * @Description: 销假管理
 * @Email:1792916664@qq.com
 */

@RestController
@RequestMapping("emp_cancel")
public class EmpCancelController {

    @Autowired
    private EmpCancelService empCancelService;

    /**
     * 销假申请
     *
     * @param empCancel
     * @return
     */
    @PostMapping("addEmpCancel")
    public String addEmpCancel(@RequestBody EmpCancel empCancel) {
        if (empCancel.getCanceldocument() == null) {
            return "销假凭据不能为空";
        }
        return empCancelService.addEmpCancel(empCancel);
    }

    /**
     * 销假列表
     *
     * @return
     */
    @GetMapping("getEmpCancelList")
    public List<EmpCancel> getEmpCancelList() {
        return empCancelService.list();
    }

    /**
     * 审批销假申请
     *
     * @param empCancel
     * @return
     */
    @PostMapping("modifyEmpCancel")
    public String modifyEmpCancel(@RequestBody EmpCancel empCancel) {
        if (empCancel.getId() == null) {
            return "无此申请";
        }

        empCancelService.updateById(empCancel);

        return "审批通过";
    }
}
